 package com.huawei.push.service.impl;

 import com.cloud.apigateway.sdk.utils.Client;
 import com.cloud.apigateway.sdk.utils.Request;
 import com.huawei.push.service.AuthCodeService;
 import com.huawei.push.util.SSLCipherSuiteUtil;
 import java.io.IOException;
 import org.apache.http.HttpEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.util.EntityUtils;
 import org.springframework.stereotype.Service;

 @Service
 public class AuthCodeServiceImpl implements AuthCodeService {
   public String authCode(String url, String license) throws IOException {
     CloseableHttpClient client = null;
     String authCode = "";
     try {
       Request request = new Request();
       request.setKey("HPUAKTOQKY5QR6HXZ3UW");
       request.setSecret("pk7UNReCaYy42bsLoDlv2oQvBG9qkXiTpvWFVBlB");
       request.setMethod("POST");
       request.setUrl(url);
       request.addHeader("Content-Type", "application/json");
       request.setBody("{\"license_list\":[\"" + license + "\"]}");
       HttpRequestBase signedRequest = Client.sign(request, "SDK-HMAC-SHA256");
       client = (CloseableHttpClient)SSLCipherSuiteUtil.createHttpClient("TLSv1.2");
       CloseableHttpResponse closeableHttpResponse = client.execute((HttpUriRequest)signedRequest);
       HttpEntity resEntity = closeableHttpResponse.getEntity();
       if (resEntity != null)
         authCode = EntityUtils.toString(resEntity, "UTF-8");
     } catch (Exception e) {
     e.printStackTrace();
     } finally {
       if (client != null)
         client.close();
     }
     return authCode;
   }
 }